package cn.seaboot.admin.mvc.cors;

import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;

/**
 * 跨域配置一览：
 * ant-path: 系统接口
 * <p>
 * Access-Control-Allow-Origin:         允许访问的域名
 * Access-Control-Allow-Methods:        允许访问的请求方式
 * Access-Control-Allow-Headers:        允许使用的 Header
 * Access-Control-Allow-Credentials:    是否允许用户发送、处理 Cookie
 * Access-Control-Max-Age:              预检有效期，单位为秒。有效期内，不需要重复发送预检请求
 * Access-Control-Expose-Headers:       Header 白名单，不设置的话，客户端读不到 Header 的内容
 *
 * @author Mr.css
 * @version 2022-03-09 16:55
 */
@Component
@ConfigurationProperties(prefix = "boot-cross-domain")
public class CorsProperties implements Serializable {
    private static final long serialVersionUID = -3682297338044962128L;
    /**
     * 路径，Controller提供的接口
     */
    @Size( max = 64)
    @Schema(description = "路径")
    private String antPath;
    /**
     * 允许访问的IP
     */
    @Size( max = 64)
    @Schema(description = "允许访问的域名")
    private String allowedOrigin;
    /**
     * 开放请求头
     */
    @Size( max = 64)
    @Schema(description = "允许的请求头")
    private String allowedHeader;
    /**
     * 开放请求方式
     */
    @Size( max = 32)
    @Schema(description = "允许的请求方式")
    private String allowedMethod;
    /**
     * 白名单Header
     */
    @Size( max = 64)
    @Schema(description = "白名单Header")
    private String exposedHeader;
    /**
     * 预检请求有效期
     */
    @Schema(description = "预检请求有效期")
    private Integer maxAge;
    /**
     * 允许携带凭证
     */
    @Schema(description = "允许携带凭证")
    private Boolean allowCredentials;

    private List<CorsProperties> config;

    public String getAntPath() {
        return antPath;
    }

    public void setAntPath(String antPath) {
        this.antPath = antPath;
    }

    public String getAllowedOrigin() {
        return allowedOrigin;
    }

    public void setAllowedOrigin(String allowedOrigin) {
        this.allowedOrigin = allowedOrigin;
    }

    public String getAllowedHeader() {
        return allowedHeader;
    }

    public void setAllowedHeader(String allowedHeader) {
        this.allowedHeader = allowedHeader;
    }

    public String getAllowedMethod() {
        return allowedMethod;
    }

    public void setAllowedMethod(String allowedMethod) {
        this.allowedMethod = allowedMethod;
    }

    public String getExposedHeader() {
        return exposedHeader;
    }

    public void setExposedHeader(String exposedHeader) {
        this.exposedHeader = exposedHeader;
    }

    public Integer getMaxAge() {
        return maxAge;
    }

    public void setMaxAge(Integer maxAge) {
        this.maxAge = maxAge;
    }

    public Boolean getAllowCredentials() {
        return allowCredentials;
    }

    public void setAllowCredentials(Boolean allowCredentials) {
        this.allowCredentials = allowCredentials;
    }

    public List<CorsProperties> getConfig() {
        return config;
    }

    public void setConfig(List<CorsProperties> config) {
        this.config = config;
    }

    @Override
    public String toString() {
        return "CrossDomainProperties{" +
                "antPath='" + antPath + '\'' +
                ", allowedOrigin='" + allowedOrigin + '\'' +
                ", allowedHeader='" + allowedHeader + '\'' +
                ", allowedMethod='" + allowedMethod + '\'' +
                ", exposedHeader='" + exposedHeader + '\'' +
                ", maxAge=" + maxAge +
                ", allowCredentials=" + allowCredentials +
                ", config=" + config +
                '}';
    }
}